package com.yaozheng.vocationaltraining.view.exam;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.iview.IItemView;
import com.yaozheng.vocationaltraining.utils.TimeUtils;
import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.view.ExamProgressStatusView;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by Administrator on 2017/9/3.
 */
@EViewGroup(R.layout.view_item_limited_challenge)
public class ItemLimitedChallengeView extends LinearLayout {
    /**
     * 试卷状态
     */
    @ViewById
    TextView examProgressStatusView;
    @ViewById
    TextView paperTitleText, paperDurationText, passingScoreText;

//    IItemView iItemView;

    int position;

//    private JSONObject currPaperJsonObject;

    public ItemLimitedChallengeView(Context context) {
        super(context);
    }

    public ItemLimitedChallengeView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void loadData(int position, JSONObject paperJsonObject) {
        this.position = position;
//        this.currPaperJsonObject = paperJsonObject;
        paperTitleText.setText(TypeUtils.getJsonString(paperJsonObject,
                "subject", ""));
        String startTime = TypeUtils.getJsonString(paperJsonObject, "startTime", "");
        String endTime = TypeUtils.getJsonString(paperJsonObject, "endTime", "");
        paperDurationText.setText(getResources().getString(
                R.string.assignmentDurationStr,
                startTime + "-" + endTime));
//        passingScoreText.setText(getResources().getString(
//                R.string.passingScoreStr,
//                TypeUtils.getJsonInteger(paperJsonObject, "passing_score", 0)));
        boolean start = TypeUtils.getJsonBoolean(paperJsonObject, "start");
        long startTimeLong = TimeUtils.stringToTime(startTime);
        long endTimeLong = TimeUtils.stringToTime(endTime);
        long currTime = System.currentTimeMillis();
        if (start || (currTime >= startTimeLong && currTime <= endTimeLong)) {
            //参加考试
            examProgressStatusView.setText("参加考试");
            examProgressStatusView.setSelected(true);
        } else {
            //已过期
            examProgressStatusView.setText("已过期");
            examProgressStatusView.setSelected(false);
        }
    }
}
